package com.sunk.springbootmybatisplus.controller;

import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.baomidou.mybatisplus.plugins.Page;
import com.sunk.springbootmybatisplus.entity.User;
import com.sunk.springbootmybatisplus.service.IUserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/test")
public class testController {
    @Autowired
    private IUserService userService;

    @RequestMapping("/1222")
    public String test1(){
        System.out.println("测试提交");
        return "4431";
    }

    @GetMapping("/test")
    public Page<User> test() {
        User u=new User();
        u.setUserAccount("haha");
        u.setUserPassword("1234");
        return userService.selectPage(
                new Page<User>(0, 12),
                new EntityWrapper<User>()
        );
    }

    @GetMapping("/test1")
    public Page<User> test123() {
        return userService.selectPage(
                new Page<User>(0, 12),
                new EntityWrapper<User>()
                        .eq("user_account", "haha")
                        .eq("user_password","1234")
        );
    }

    @GetMapping("/test2")
    public Page<User> pae() {
        return userService.selectUserPage(new Page<>(0,2));
    }


    @GetMapping("/insert")
    public void test1234() {
        User u=new User();
        u.setUserAccount("haha");
        u.setUserPassword("1234");
        userService.insert(u);
        System.out.println(u.getUserId());
    }
}
